/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grafrajz.dialogs;

import grafrajz.GrafRajzWindow;
import grafrajz.GraphLogic;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author adam_fejes_dell
 * Új csúcs létreozó párbeszédablak
 */
public class NewNodeWindow extends JDialog{
    
    private JButton okBtn, cancelBtn;
    private JTextField nodeName;
    private JPanel mainPanel, buttonsPanel;
    
    public NewNodeWindow(final GrafRajzWindow frame, final GraphLogic gLogic) {
        super(frame);
        setTitle("Create new node");
        setSize(new Dimension(200, 100));
        setLocationRelativeTo(frame);
        
        
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayout(2, 1, 5, 5));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        
        nodeName = new JTextField();
        mainPanel.add(nodeName);
        
        buttonsPanel = new JPanel();
        buttonsPanel.setLayout(new BorderLayout());
        
        mainPanel.add(buttonsPanel);
        
        okBtn = new JButton("OK");
        okBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                gLogic.addNode(nodeName.getText().toString());
                frame.updateWindow(frame);
                dispose();
            }
        });
        buttonsPanel.add(okBtn, BorderLayout.WEST);
        
        cancelBtn = new JButton("Cancel");
        cancelBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        buttonsPanel.add(cancelBtn, BorderLayout.EAST);
        
        add(mainPanel);
    }
  
    
    
}
